import { $http } from '@/utils';
import { $ResponseCode } from '@/utils/const/env';
import { usePlatformStore, useStatusStore, useWebConfigStore, useRefs } from "@/stores";
export const Config = {
    webconfig: () => {
        return new Promise((resolve, reject) => {
            const PlatformStore = usePlatformStore();
            const { PLATFORM } = useRefs(PlatformStore);
            $http.get('Config/index', {
                data: {
                    platform: PLATFORM.value.platform,
                    platforms: PLATFORM.value.platforms
                }
            }).then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    if (res.data.single_mch) {
                        const StatusStore = useStatusStore();
                        StatusStore.removeTabbarMch();
                    }
                    const WebConfigStore = useWebConfigStore();
                    WebConfigStore.setWebConfig(res.data);
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        });
    },
    channels: () => {
        return new Promise((resolve, reject) => {
            $http.get('Config/channels').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        });
    },
    dealer: () => {
        return new Promise((resolve, reject) => {
            $http.get('Config/dealer').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        });
    },
    salesman: () => {
        return new Promise((resolve, reject) => {
            $http.get('Config/salesman').then((res: any) => {
                if (res.code === $ResponseCode.SUCCESS) {
                    resolve(res.data);
                } else {
                    reject(res);
                }
            }).catch(() => {
                reject({ msg: '服务器繁忙，请稍后再试' });
            })
        });
    }
}